﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using MobileSales.Model.Util;
using System.ComponentModel.DataAnnotations;
using MobileSales.Model.Localization;

namespace MobileSales.Model.Documents
{
    [DataContract]
    public class Document
    {
        [DataMember]
        public int Id { get; set; }
        [DataMember]
        public int OrderId { get; set; }
        [DataMember]
        [Display(Name = "DocumentType", ResourceType = typeof(ModelStrings))]
        public DocumentType DocumentType { get; set; }
        [DataMember]
        [Display(Name = "PaymentMethod", ResourceType = typeof(ModelStrings))]
        public PaymentMethod PaymentMethod { get; set; }
        [DataMember]
        [Display(Name = "DocumentNo", ResourceType = typeof(ModelStrings))]
        [RegularExpression(RegExp.IntegerRegexp, ErrorMessageResourceName = "InvalidInteger", ErrorMessageResourceType = typeof(ValidationStrings))]
        public int DocumentNo { get; set; }

        [DataMember(Name="CreationDate")]
        private string _creationDate { get; set; }
        public DateTime CreationDate
        {
            get
            {
                if (_creationDate != null) return DateUtil.Deserialize(_creationDate);
                return DateTime.MinValue;
            }
            set
            {
                _creationDate = DateUtil.Serialize(value);
            }
        }
        [DataMember(Name = "PaymentDate")]
        private string _paymentDate { get; set; }
        [Display(Name = "PaymentDate", ResourceType = typeof(ModelStrings))]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        public DateTime PaymentDate
        {
            get
            {
                if (_paymentDate != null) return DateUtil.Deserialize(_paymentDate);
                return DateTime.MinValue;
            }
            set
            {
                _paymentDate = DateUtil.Serialize(value);
            }
        }

        [DataMember]
        public string ClientName { get; set; }
        [DataMember]
        public string ClientName2 { get; set; }
        [DataMember]
        public string ClientNip { get; set; }
        [DataMember]
        public string ClientZipcode { get; set; }
        [DataMember]
        public string ClientCity { get; set; }
        [DataMember]
        public string ClientStreet { get; set; }
        [DataMember]
        public string ClientPhone { get; set; }
        [DataMember]
        public string ClientFax { get; set; }
        [DataMember]
        public string ClientInfo { get; set; }
        [DataMember]
        [Display(Name = "IsPaid", ResourceType = typeof(ModelStrings))]
        public bool IsPaid { get; set; }
        [DataMember]
        public IEnumerable<DocumentElement> Items { get; set; }

    }
}
